package com.juzi.wopu.web;

import javax.servlet.http.Cookie;

import com.juzi.wopu.domain.Employee;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{
	
	private static final long serialVersionUID = 1L;
	  
	public static final String RELOAD = "reload";
	  
	public static final String USER_IN_SESSION = "userInSession";
	
	public static final String changePassword="changePassword";

	protected void putContext(String key, Object value) {
		ActionContext.getContext().put(key, value);
	}
	
	protected Object getContext(String key) {
		return ActionContext.getContext().get(key);
	}
	  
	protected void setLoginUser(Employee loginUser){
		ActionContext.getContext().getSession().put(USER_IN_SESSION, loginUser);
	}
	
	protected Employee getLoginUser(){
		return (Employee)ActionContext.getContext().getSession().get(USER_IN_SESSION);
	}
	
	public String getCookieValue(Cookie[] cookies, String str) {
		String result = null;
		for (Cookie cookie : cookies) {
			if (cookie.getName().equals(str)) {
				result = cookie.getValue();
				break;
			}
		}
		return result;
	}
}
